<?php

use Rester\Validator;

class UserModel extends BaseModel
{
    //表名
    protected $table = 'user';

    const USER_TYPE_PERSON = 1;
    const USER_TYPE_ORG = 2;

    /**
     * 修改个人信息校验
     * @param array $params
     * @return array
     */
    public static function validatorUser(array $params)
    {
        $data = $personData = $userOrgData = $rules = [];
        if ($params['type'] == 1) {
            switch ($params['step']) {
                case 1:
                    $data = [
                        'is_long-effective' => isset($params['is_long-effective']) ? $params['is_long-effective']: '' ,
                        'certificate_valid_date' => isset($params['certificate_valid_date'])? $params['certificate_valid_date'] : '',
                        'marriage' => isset($params['marriage']) ? $params['marriage'] : '',
                        'vocational_type' => isset($params['vocational_type']) ? $params['vocational_type'] : '',
                        'relation_address' => isset($params['relation_address']) ? $params['relation_address'] : '',
                        'zip_code' => isset($params['zip_code']) ? $params['zip_code'] : '',
                        'sex' => isset($params['sex']) ? $params['sex'] : '',
                        'type' => isset($params['type']) ? $params['type'] : '',
                        'nationality' => isset($params['nationality']) ? $params['nationality'] : '',
                    ];
                    $rules = [
                        'is_long-effective' => 'required|max:1|min:0',
                        'certificate_valid_date' => 'required|string',
                        'marriage' => 'required|max:1|min:0',
                        'vocational_type' => 'required|max:6|min:1',
                        'relation_address' => 'required|string|min:8',
                        'zip_code' => 'required|string|max:6|min:5',
                        'sex' => 'required|max:1|min:0',
                        'type' => 'required|max:2|min:1',
                        'nationality' => 'required|max:2|min:1',
                    ];
                    break;
                case 2:
                    $data = [
                        'custodian_name' => isset($params['custodian_name']) ? $params['custodian_name'] : '',
                        'custodian_id_type' => isset($params['custodian_id_type'])? $params['custodian_id_type'] : '',
                        'custodian_identity_id' => isset($params['custodian_identity_id']) ? $params['custodian_identity_id'] : '',
                        'custodian_certificate_date' => isset($params['custodian_certificate_date']) ? $params['custodian_certificate_date'] :'',
                        'type' => isset($params['type']) ? $params['type'] :'',
                    ];
                    $rules = [
                        'custodian_name' => 'required|string|max:10|min:2',
                        'custodian_id_type' => 'required|max:2|min:1',
                        'custodian_identity_id' => 'required|max:18|min:15',
                        'custodian_certificate_date' => 'required|string',
                        'type' => 'required|max:2|min:1',
                    ];
                    break;
                case 3:
                    $data = [
                        'net_asset' => isset($params['net_asset']) ? $params['net_asset'] :'',
                        'financial_net_asset' => isset($params['financial_net_asset']) ? $params['financial_net_asset'] :'',
                        'recent_three_years_reincome' => isset($params['recent_three_years_reincome']) ? $params['recent_three_years_reincome'] : '',
                        'invest_term' => isset($params['invest_term'])?$params['invest_term']:'',
                        'related_work_term' => isset($params['related_work_term'])?$params['related_work_term']:'',
                        'is_financial_industry' => isset($params['is_financial_industry']) ?$params['is_financial_industry']:'',
                        'promise' => isset($params['promise'])?$params['promise']:'',
                        'promise_benifit_self' => isset($params['promise_benifit_self']) ? $params['promise_benifit_self']:'',
                        'type' => isset($params['type']) ? $params['type'] :'',
                    ];
                    $rules = [
                        'net_asset' => 'required|min:1|max:7',
                        'financial_net_asset' => 'required|max:7|min:1',
                        'recent_three_years_reincome' => 'required|max:5|min:1',
                        'invest_term' => 'required|max:2|min:1',
                        'related_work_term' => 'required|max:2|min:1',
                        'is_financial_industry' => 'required|max:2|min:1',
                        'promise' => 'required|max:2|min:1',
                        'promise_benifit_self' => 'required|max:2|min:1',
                        'type' => 'required|max:2|min:1',
                    ];
                    $personData = [
                        'promise_benifit_self' => $params['promise_benifit_self']
                    ];
                    break;
            }

            $validator = Validator::getInstance()->make($data, $rules);

            return [
                'validator' => $validator,
                'data' => $personData
            ];

        } else {
            if ($params['type'] == 2) {
                switch ($params['step']) {
                    case 1:
                        $data = [
                            'company_property' => isset($params['company_property'])?$params['company_property']:'',
                            'vailddate' => isset($params['vailddate'])?$params['vailddate']:'',
                            'relation_address' => isset($params['relation_address'])?$params['relation_address']:'',
                            'type' => isset($params['type']) ? $params['type'] :'',
                        ];
                        $rules = [
                            'company_property' => 'required|max:7|min:1',
                            'vailddate' => 'required|string',
                            'relation_address' => 'required|string|max:65532|min:8',
                            'type' => 'required|max:2|min:1',
                        ];
                        $userOrgData = [
                            'vailddate' => $params['vailddate'],
                            'is_expert' => $params['is_expert']
                        ];
                        break;
                    case 2:
                        $data = [
                            'is_financial_industry_company' => isset($params['is_financial_industry_company'])?
                                                                $params['is_financial_industry_company']:'',
                            'is_financial_products_company' => isset($params['is_financial_products_company']) ?
                                                                $params['is_financial_products_company']:'',
                            'is_social_security_funds_company' => isset($params['is_social_security_funds_company']) ?
                                                                    $params['is_social_security_funds_company'] :'',
                            'type' => isset($params['type']) ? $params['type'] :'',
                        ];
                        $rules = [
                            'is_financial_industry_company' => 'max:2|min:1',
                            'is_financial_products_company	' => 'max:2|min:1',
                            'is_social_security_funds_company' => 'max:2|min:1',
                            'type' => 'required|max:2|min:1',
                        ];
//                        $userOrgData = [
//                            'is_social_security_funds_company' => $params['is_social_security_funds_company'],
//                        ];
                        break;
                    case 3:
                        $data = [
                            'recent_one_years_reincome' => isset($params['recent_one_years_reincome']) ?
                                                            $params['recent_one_years_reincome'] :'',
                            'recent_one_financial_assets' => isset($params['recent_one_financial_assets']) ?
                                                                $params['recent_one_financial_assets'] :'',
                            'invest_term' => isset($params['invest_term']) ? $params['invest_term'] :'',
                            'promise_benifit_self' => isset($params['promise_benifit_self']) ? $params['promise_benifit_self'] :'',
                            'promise' => isset($params['promise']) ? $params['promise'] :'',
                            'type' => isset($params['type']) ? $params['type'] :'',
                        ];
                        $rules = [
                            'recent_one_years_reincome' => 'required|max:8|min:1',
                            'recent_one_financial_assets' => 'required|max:8|min:1',
                            'invest_term' => 'required|max:2|min:1',
                            'promise_benifit_self' => 'required|max:11|min:1',
                            'promise' => 'required|max:2|min:1',
                            'type' => 'required|max:2|min:1',
                        ];
                        $userOrgData = [
                            'promise_benifit_self' => $params['promise_benifit_self']
                        ];
                        break;
                }

                $validator = Validator::getInstance()->make($data, $rules);
                return [
                    'validator' => $validator,
                    'data' => $userOrgData
                ];
            }
        }

    }

    /**
     * 机构录入信息校验
     * @param array $params
     * @return \Illuminate\Validation\Validator
     */
    public static function validatorOrgUser(array $params)
    {
        $data = $rules = [];
        switch ($params['step']) {
            case 1:
                $data = [
                    'legal_person_name' => isset($params['legal_person_name']) ? $params['legal_person_name'] :'',
                    'legal_person_card' => isset($params['legal_person_card'])?$params['legal_person_card']:'',
                    'legal_person_vailddate' => isset($params['legal_person_vailddate'])?$params['legal_person_vailddate']:'',
                    'long_effective_l' => isset($params['long_effective_l'])?$params['long_effective_l']:'',
                    'legal_person_gender' => isset($params['legal_person_gender'])?$params['legal_person_gender']:'',
                    'auth_person_name' => isset($params['auth_person_name'])?$params['auth_person_name']:'',
                    'auth_person_card' => isset($params['auth_person_card'])?$params['auth_person_card']:'',
                    'auth_person_vailddate' => isset($params['auth_person_vailddate'])?$params['auth_person_vailddate']:'',
                    'long_effective_a' => isset($params['long_effective_a'])?$params['long_effective_a']:'',
                    'auth_person_gender' => isset($params['auth_person_gender'])?$params['auth_person_gender']:'',
                    'auth_title' => isset($params['auth_title'])?$params['auth_title']:'',
                ];
                $rules = [
                    'legal_person_name' => 'required|string|max:16|min:1',
                    'legal_person_card' => 'required|string|max:18|min:15',
                    'legal_person_vailddate' => 'required|string',
                    'long_effective_l' => 'required|max:2|min:0',
                    'legal_person_gender' => 'required|max:1|min:0',
                    'auth_person_name' => 'required|string|max:16|min:1',
                    'auth_person_card' => 'required|string|max:18|min:15',
                    'auth_person_vailddate' => 'required|string',
                    'long_effective_a' => 'required|max:1|min:0',
                    'auth_person_gender' => 'required|max:1|min:0',
                    'auth_title' => 'required|string',
                ];
                break;
            case 2:
                $data = [
                    'product_type' => isset($params['product_type'])?$params['product_type']:'',
                    'fill_org_name' => isset($params['fill_org_name']) ? $params['fill_org_name'] :'',
                    'fill_time' => isset($params['fill_time'])?$params['fill_time']:'',
                    'create_date' => isset($params['create_date'])?$params['create_date']:'',
                    'fill_num' => isset($params['fill_num'])?$params['fill_num']:'',
                    'continue_time' => isset($params['continue_time'])?$params['continue_time']:'',
                    'product_size' => isset($params['product_size'])?$params['product_size']:'',
                    'product_manager' => isset($params['product_manager'])?$params['product_manager']:'',
                    'manager_qualification' => isset($params['manager_qualification'])?$params['manager_qualification']:'',
                    'manager_num' => isset($params['manager_num'])?$params['manager_num']:'',
                    'product_controller' => isset($params['product_controller'])?$params['product_controller']:''
                ];
                $rules = [
                    'product_type' => 'required|max:7|min:1',
                    'fill_org_name' => 'required|string',
                    'fill_time' => 'required|string',
                    'create_date' => 'required|string',
                    'fill_num' => 'required|string',
                    'continue_time' => 'required|string',
                    'product_size' => 'required|string',
                    'product_manager' => 'required|string',
                    'manager_qualification' => 'required|string',
                    'manager_num' => 'required|string',
                    'product_controller' => 'required|string'
                ];
                break;
        }
        $validator = Validator::getInstance()->make($data, $rules);
        return $validator;
    }
}